package com.qidian.md.controller;

import com.qidian.md.service.UnitmeasureService;
import com.qidian.mes.pojo.md.Unitmeasure;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 18林梦雅
 * @Company 起点编程
 * @Time 2023/10/30 16:48
 * @Description
 */
@RestController
@RequestMapping("/unitmeasure")
@CrossOrigin
public class UnitmeasureController {
    @Autowired
    private UnitmeasureService unitmeasureService;

    @GetMapping("/list")
    public MESResult list(Unitmeasure unitmeasure, @RequestParam(defaultValue="1")int page, @RequestParam(defaultValue="10")int limit){
        System.out.println(unitmeasure+"++++++++++++++++++++++++++++++++++++++++++");
        return unitmeasureService.queryByPage(unitmeasure,page,limit);
    }


    /**controller
     * 添加单位接口
     * 请求方法： POST
     * url： /unitmeasure/save
     * 参数：
     * 格式：JSON
     * 参数的内容：unitmeasurename,unitmeasurePass
     * 响应结果：
     * 成功： ｛code:200,msg:"",data:null｝
     * 失败：
     * 失败｛code:500,msg:"错误信息",data:null｝
     * 重名 {code: 300,msg:"名字重复",data:""}
     * @param unitmeasure
     * @return
     */
    @PostMapping("/save")
    public MESResult save(@RequestBody Unitmeasure unitmeasure){
        return unitmeasureService.addUnitmeasure(unitmeasure);
    }

    /**controller
     * 请求方法： GET
     * url : /unitmeasure/get
     * 参数： measureId(必须，要查询的客户编号)
     * 响应：
     *  成功： `{code:200,msg:"",data:{...}}`
     *  失败：`{code:400,msg:"没有数据",data:null}`
     * @param measureId
     * @return
     */
    @GetMapping("/get")
    public MESResult get(Long measureId){
        return   unitmeasureService.queryById(measureId);
    }

    /**编辑客户
     请求方法： PUT/POST
     url： /unitmeasure/edit
     参数 : measureId(必须),measurename
     响应结果：
     成功： ｛code:200,msg:"",data:null｝
     失败：
     失败｛code:500,msg:"错误信息",data:null｝
     重名 {code: 300,msg:"名字重复",data:""}
     */
    @PutMapping("/update")
    public MESResult update(@RequestBody Unitmeasure unitmeasure){
        System.out.println(unitmeasure+"+++++++++++++++++++++++++++++++++++++++++");
        return unitmeasureService.update(unitmeasure);
    }

    /**
     * 根据Id删除单位数据,删除是将是否启用改为0,将搜索显示是更改为除了0其他显示
     * @param measureId
     * @return
     */
    @DeleteMapping("/{measureId}")
    public MESResult deleteById(@PathVariable Long measureId){//注意这里的注解是因为用字段为url
        return unitmeasureService.deleteUpdateStatus(measureId);
    };













}
